
#include "stdafx.h"
#include "ChatWnd.h"
#include <msg.h>
#include "playerControl_t.h"

extern hgeFontCN*	fontCN;

ChatWnd::ChatWnd( GUIManager * pGUIManager )
{
	m_pGUIManager	=	pGUIManager;
}


void		ChatWnd::Init()
{
	Window* chat_wnd	=	CreateWnd( m_pGUIManager, "chat_wnd", NULL, "pmClientRes//UI//ChooseMapListBoxBack.PNG" );
	chat_wnd->SetPos( 20.0f, 180.0f );
	chat_wnd->SetShow(false);
	chat_wnd->SetTransparence(50);

	EditBox*	chat_eb	=	CreateEditBox( m_pGUIManager, "chat_eb", chat_wnd, fontCN );
	chat_eb->SetPosToParent( 30.0f, 370.0f );
	chat_eb->SetSize( 260, 20 );

	Button*	chat_send_btn	=	CreateButton( m_pGUIManager, "chat_send_btn", chat_wnd, 
		"pmClientRes//UI//OKBtn.PNG", "pmClientRes//UI//OKBtn.PNG", "pmClientRes//UI//OKBtn.PNG" );

	chat_send_btn->SetPosToParent( 300.0f, 380.0f );
	chat_send_btn->SetTransparence(70);
	chat_send_btn->RegisterCallBackFun(chat_send_btn_proc);


	ListBox* chat_lb	=	CreateListBox( m_pGUIManager, "chat_lb", chat_wnd, 14 );
	chat_lb->SetPosToParent( 10.0f, 0.0f );
	chat_lb->SetSBSize( 40, 350 );
	chat_lb->SetSBPosToListBox( 375, 40 );
	chat_lb->SetTextPosToListBox( 60,60 );

	RECT	rcListBack		=	GetRect( 0, 0, 0, 0 );
	RECT	rcMInButton1	=	GetRect( 44, 0, 88, 40 );
	RECT	rcMOutButton1	=	GetRect( 0, 0, 44, 40 );
	RECT	rcMClickButton1	=	GetRect( 0, 40, 44, 80 );
	RECT	rcMInButton2	=	GetRect( 44, 0, 88, 40 );
	RECT	rcMOutButton2	=	GetRect( 0, 0, 44, 40 );
	RECT	rcMClickButton2	=	GetRect( 0, 40, 44, 80 );
	RECT	rcScrollButton	=	GetRect( 44, 40, 88, 80 );


	LoadListBoxRes( chat_lb, 
		"pmClientRes//UI//ChooseMapListBoxBack.PNG", rcListBack, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMInButton1, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMOutButton1, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMClickButton1, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMInButton2, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMOutButton2, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcMClickButton2, 
		"pmClientRes//UI//ScorllBarBtn.PNG", rcScrollButton, 
		"pmClientRes//UI//ScorllBarBack.PNG" );

	chat_lb->SetLineWords(25);
	chat_lb->SetCurItem(0);
	chat_lb->SetTransparence(70);
}


int		chat_send_btn_proc( GUIManager * pGUIManager, GUIID self, CVarList msg )
{
	if ( msg.GetValueCount() == 0 )
	{
		return 0;
	}

	MSG_WM	wmMsg	=	(MSG_WM)msg.GetIntValue(0);

	switch (wmMsg)
	{
	case MSG_WM_MOUSE_IN:
		{
		}
		break;

	case MSG_WM_LBUTTON_UP:
		{
			EditBox* chat_eb	=	(EditBox*)pGUIManager->GetPointerByName("chat_eb");
			string text	=	chat_eb->GetText();
			
			if ( text.empty() )
			{
				return 0;
			}

			CVarList msg;
			msg<<CLS_MSG_CHAT<<text;

			SocketMgr::GetSingleton()->Custom("ppClient",msg.GetInfo());
		}
		break;

	default:
		{
		}
		break;
	}

	return 1;
}